package com.android.wlw_local.otg;


import android.os.Build;

import com.android.commonlib.loop.HandlerLooper;

import tw.com.prolific.driver.pl2303.PL2303Driver;

/**
 * Created by zhuqin on 2018/3/6.
 */

public class OTGConfigStore {

    private PL2303Driver.BaudRate mBaudrate = PL2303Driver.BaudRate.B9600;
    private PL2303Driver.DataBits mDataBits = PL2303Driver.DataBits.D8;
    private PL2303Driver.Parity mParity = PL2303Driver.Parity.NONE;
    private PL2303Driver.StopBits mStopBits = PL2303Driver.StopBits.S1;
    private PL2303Driver.FlowControl mFlowControl = PL2303Driver.FlowControl.OFF;

    /**
     * 波特率
     */
    public static final int BPS9600  = 9600 ;
    public static final int BPS19200 = 19200 ;
    public static final int BPS115200 = 115200 ;

    /**
     * 波特率
     */
    int bpsValue ;
    /**
     * 局域网端口
     */
    int post ;
    /**
     * IP
     */
    String ip ;
    /**
     * 数据位
     */
    int dataBit ;
    /**
     * 查询维度
     */
    boolean isQueryTemperature ;
    /**
     * 查询水位
     */
    boolean isQueryWaterLevel ;
    /**
     * 自动加水
     */
    boolean isAutoWater ;

    private volatile static OTGConfigStore mInstance = null ;


    /**
     * 单例
     * @return
     */
    public static OTGConfigStore getInstance(){
        if(mInstance == null){
            synchronized (OTGConfigStore.class){
                if(mInstance == null){
                    mInstance = new OTGConfigStore.Builder().build();
                }
            }
        }
        return mInstance ;
    }


    private OTGConfigStore(Builder builder){
        this.bpsValue = builder.bpsValue ;
        this.post = builder.post;
        this.ip = builder.ip ;
        this.dataBit = builder.dataBit;
        this.isQueryTemperature = builder.isQueryTemperature ;
        this.isQueryWaterLevel = builder.isQueryWaterLevel ;
        this.isAutoWater = builder.isAutoWater ;
    }

    public OTGConfigStore() {
    }

    static class Builder{
        int bpsValue = BPS115200;
        int post ;
        String ip ;
        int dataBit ;
        boolean isQueryTemperature = true;
        boolean isQueryWaterLevel = true;
        boolean isAutoWater = true;
        public Builder bpsValue(int bpsValue){
            this.bpsValue=bpsValue;
            return this;
        }
        public Builder post(int post){
            this.post = post ;
            return this ;
        }

        public Builder ip(String ip ){
            this.ip = ip ;
            return this ;
        }
        public Builder dataBit(int dataBit ){
            this.dataBit = dataBit ;
            return this ;
        }
        public Builder isQueryTemperature(boolean isQueryTemperature ){
            this.isQueryTemperature = isQueryTemperature ;
            return this ;
        }
        public Builder isQueryWaterLevel(boolean isQueryWaterLevel ){
            this.isQueryWaterLevel = isQueryWaterLevel ;
            return this ;
        }
        public Builder isAutoWater(boolean isAutoWater ){
            this.isAutoWater = isAutoWater ;
            return this ;
        }

        public OTGConfigStore build(){
            return new OTGConfigStore(this);
        }
    }

    public int getBpsValue() {
        return bpsValue;
    }

    public void setBpsValue(int bpsValue) {
        this.bpsValue = bpsValue;
    }

    public int getPost() {
        return post;
    }

    public void setPost(int post) {
        this.post = post;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public int getDataBit() {
        return dataBit;
    }

    public void setDataBit(int dataBit) {
        this.dataBit = dataBit;
    }

    public boolean isQueryTemperature() {
        return isQueryTemperature;
    }

    public void setQueryTemperature(boolean queryTemperature) {
        isQueryTemperature = queryTemperature;
    }

    public boolean isQueryWaterLevel() {
        return isQueryWaterLevel;
    }

    public void setQueryWaterLevel(boolean queryWaterLevel) {
        isQueryWaterLevel = queryWaterLevel;
    }

    public boolean isAutoWater() {
        return isAutoWater;
    }

    public void setAutoWater(boolean autoWater) {
        isAutoWater = autoWater;
    }
}
